package org.mat.ipaas.ucenter.service.api.system;

import com.alibaba.fastjson.JSONObject;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.constant.CommonConstant;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysPermissionDTO;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysPermissionDataRuleDTO;
import org.mat.ipaas.ucenter.service.dto.system.model.SysPermissionTreeDTO;
import org.mat.ipaas.ucenter.service.dto.system.model.TreeModelDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @Author scott
 * @since 2018-12-21
 */
@FeignClient(name = "mat-ipaas-ucenter-service", contextId = "sys-permission-rest-api")
public interface SysPermissionRestAPI {

    /**
     * 加载数据节点
     *
     * @return
     */
    //@RequiresPermissions("system:permission:list")
    @RequestMapping(value = "/sys/permission/list", method = RequestMethod.GET)
    MatApiResponse<List<SysPermissionTreeDTO>> list(@SpringQueryMap SysPermissionDTO sysPermissionDTO);

    /**
     * 系统菜单列表(一级菜单)
     *
     * @return
     */
    @RequestMapping(value = "/sys/permission/getSystemMenuList", method = RequestMethod.GET)
    MatApiResponse<List<SysPermissionTreeDTO>> getSystemMenuList();

    /**
     * 查询子菜单
     *
     * @param parentId
     * @return
     */
    @RequestMapping(value = "/sys/permission/getSystemSubmenu", method = RequestMethod.GET)
    MatApiResponse<List<SysPermissionTreeDTO>> getSystemSubmenu(@RequestParam("parentId") String parentId);

    /**
     * 查询子菜单
     *
     * @param parentIds 父ID（多个采用半角逗号分割）
     * @return 返回 key-value 的 Map
     */
    @GetMapping("/sys/permission/getSystemSubmenuBatch")
    MatApiResponse getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds);

    /**
     * 查询用户拥有的菜单权限和按钮权限
     *
     * @return
     */
    @RequestMapping(value = "/sys/permission/getUserPermissionByToken", method = RequestMethod.GET)
    //@DynamicTable(value = DynamicTableConstant.SYS_ROLE_INDEX)
    MatApiResponse<?> getUserPermissionByToken(@RequestHeader(CommonConstant.VERSION) String version);

    /**
     * 【vue3专用】获取
     * 1、查询用户拥有的按钮/表单访问权限
     * 2、所有权限 (菜单权限配置)
     * 3、系统安全模式 (开启则online报表的数据源必填)
     */
    @RequestMapping(value = "/sys/permission/getPermCode", method = RequestMethod.GET)
    MatApiResponse<?> getPermCode();

    /**
     * 添加菜单
     *
     * @param permission
     * @return
     */
    //@RequiresPermissions("system:permission:add")
    @RequestMapping(value = "/sys/permission/add", method = RequestMethod.POST)
    MatApiResponse<SysPermissionDTO> add(@RequestBody SysPermissionDTO permission);

    /**
     * 编辑菜单
     *
     * @param permission
     * @return
     */
    //@RequiresPermissions("system:permission:edit")
    @RequestMapping(value = "/sys/permission/edit", method = {RequestMethod.POST})
    MatApiResponse<SysPermissionDTO> edit(@RequestBody SysPermissionDTO permission);

    /**
     * 检测菜单路径是否存在
     *
     * @param id
     * @param url
     * @return
     */
    @RequestMapping(value = "/sys/permission/checkPermDuplication", method = RequestMethod.GET)
    MatApiResponse<String> checkPermDuplication(@RequestParam(name = "id", required = false) String id, @RequestParam(name = "url") String url, @RequestParam(name = "alwaysShow") Boolean alwaysShow);

    /**
     * 删除菜单
     *
     * @param id
     * @return
     */
    //@RequiresPermissions("system:permission:delete")
    @RequestMapping(value = "/sys/permission/delete", method = RequestMethod.DELETE)
    MatApiResponse<SysPermissionDTO> delete(@RequestParam(name = "id", required = true) String id);

    /**
     * 批量删除菜单
     *
     * @param ids
     * @return
     */
    //@RequiresPermissions("system:permission:deleteBatch")
    @RequestMapping(value = "/sys/permission/deleteBatch", method = RequestMethod.DELETE)
    MatApiResponse<SysPermissionDTO> deleteBatch(@RequestParam(name = "ids", required = true) String ids);

    /**
     * 获取全部的权限树
     *
     * @return
     */
    @RequestMapping(value = "/sys/permission/queryTreeList", method = RequestMethod.GET)
    MatApiResponse<Map<String, Object>> queryTreeList();

    /**
     * 异步加载数据节点 [接口是废的,没有用到]
     *
     * @return
     */
    @RequestMapping(value = "/sys/permission/queryListAsync", method = RequestMethod.GET)
    MatApiResponse<List<TreeModelDTO>> queryAsync(@RequestParam(name = "pid", required = false) String parentId);

    /**
     * 查询角色授权
     *
     * @return
     */
    @RequestMapping(value = "/sys/permission/queryRolePermission", method = RequestMethod.GET)
    MatApiResponse<List<String>> queryRolePermission(@RequestParam(name = "roleId", required = true) String roleId);

    /**
     * 保存角色授权
     *
     * @return
     */
    //@RequiresPermissions("system:permission:saveRole")
    @RequestMapping(value = "/sys/permission/saveRolePermission", method = RequestMethod.POST)
    MatApiResponse<String> saveRolePermission(@RequestBody JSONObject json);

    /**
     * 根据菜单id来获取其对应的权限数据
     *
     * @param sysPermissionDataRuleDTO
     * @return
     */
    @RequestMapping(value = "/sys/permission/getPermRuleListByPermId", method = RequestMethod.GET)
    MatApiResponse<List<SysPermissionDataRuleDTO>> getPermRuleListByPermId(SysPermissionDataRuleDTO sysPermissionDataRuleDTO);

    /**
     * 添加菜单权限数据
     *
     * @param sysPermissionDataRuleDTO
     * @return
     */
    //@RequiresPermissions("system:permission:addRule")
    @RequestMapping(value = "/sys/permission/addPermissionRule", method = RequestMethod.POST)
    MatApiResponse<SysPermissionDataRuleDTO> addPermissionRule(@RequestBody SysPermissionDataRuleDTO sysPermissionDataRuleDTO);

    //@RequiresPermissions("system:permission:editRule")
    @RequestMapping(value = "/sys/permission/editPermissionRule", method = {RequestMethod.POST})
    MatApiResponse<SysPermissionDataRuleDTO> editPermissionRule(@RequestBody SysPermissionDataRuleDTO sysPermissionDataRuleDTO);

    /**
     * 删除菜单权限数据
     *
     * @param id
     * @return
     */
    //@RequiresPermissions("system:permission:deleteRule")
    @RequestMapping(value = "/sys/permission/deletePermissionRule", method = RequestMethod.DELETE)
    MatApiResponse<SysPermissionDataRuleDTO> deletePermissionRule(@RequestParam(name = "id", required = true) String id);

    /**
     * 查询菜单权限数据
     *
     * @param sysPermissionDataRuleDTO
     * @return
     */
    @RequestMapping(value = "/sys/permission/queryPermissionRule", method = RequestMethod.GET)
    MatApiResponse<List<SysPermissionDataRuleDTO>> queryPermissionRule(SysPermissionDataRuleDTO sysPermissionDataRuleDTO);

    /**
     * 部门权限表
     *
     * @param departId
     * @return
     */
    @RequestMapping(value = "/sys/permission/queryDepartPermission", method = RequestMethod.GET)
    MatApiResponse<List<String>> queryDepartPermission(@RequestParam(name = "departId", required = true) String departId);

    /**
     * 保存部门授权
     *
     * @return
     */
    @RequestMapping(value = "/sys/permission/saveDepartPermission", method = RequestMethod.POST)
    //@RequiresPermissions("system:permission:saveDepart")
    MatApiResponse<String> saveDepartPermission(@RequestBody JSONObject json);

}
